<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>倒计时</title>
		<style type="text/css">
		*{
			margin: 0 auto;
		}
		#Box{
			width: 550px;
			height: 500px;
			color: white;
				text-align: center;
				line-height: 80px;
				font-size: 30px;
				background: orange;
			border: 1px solid orange;
		}
		</style>
	</head>
	<body>
		<div id="Box">
			
		</div>
	</body>
	<script>
	//利用当前时间与结束时间的时差来实现倒计时
		function showtime(){
			var nowtime = new Date();
			var endtime = new Date("2020/10/16");
			var leftime = endtime.getTime()-nowtime.getTime();
			var day = Math.floor(leftime/(1000*60*60*24));
			var hours = Math.floor(leftime/(1000*60*60)%24);
			var min = Math.floor(leftime/(1000*60)%60);
			var sec = Math.floor(leftime/1000%60);
			return day + "天"+hours+"小时 "+min+"分钟"+sec+"秒" 
		}
		var box = document.getElementById("Box");
		setInterval(
			function(){
				box.innerHTML = showtime();
			},1000
		);
	</script>
</html>
